// Copyright 2006 Bret Taylor
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

#include "filelocation.h"

#include "ast.h"
#include "yaccparser.h"

namespace indie {

FileLocation* FileLocationFactory::create(const struct YYLTYPE& loc) const {
    return new FileLocation(path_, loc.first_line, loc.first_column,
			    loc.last_line, loc.last_column);
}

FileLocation* FileLocationFactory::create(const struct YYLTYPE& start,
					  const struct YYLTYPE& end) const {
    return new FileLocation(path_, start.first_line, start.first_column,
			    end.last_line, end.last_column);
}

FileLocation* FileLocationFactory::create(const Ast* loc) const {
    assert(loc != NULL);
    return new FileLocation(loc->location());
}

FileLocation* FileLocationFactory::create(const Ast* start,
					  const struct YYLTYPE& end) const {
    assert(start != NULL);
    return new FileLocation(path_, start->location().start_line(),
			    start->location().start_column(),
			    end.last_line, end.last_column);
}

FileLocation* FileLocationFactory::create(const struct YYLTYPE& start,
					  const Ast* end) const {
    assert(end != NULL);
    return new FileLocation(path_, start.first_line, start.first_column,
			    end->location().end_line(),
			    end->location().end_column());
}

FileLocation* FileLocationFactory::create(const Ast* start,
					  const Ast* end) const {
    assert(start != NULL);
    assert(end != NULL);
    return new FileLocation(path_, start->location().start_line(),
			    start->location().start_column(),
			    end->location().end_line(),
			    end->location().end_column());
}

}
